const goodsModel = require("../models/Ridgepoleid_model");
//根据id查询数据
function getitem(goods, onRetGot, onErrGot) {
    goodsModel.getgoods(goods, (ret) => onRetGot(ret ? { ret,msg:"查询成功",code:200 }:{msg:"查询失败",code:400}),(err)=>onErrGot({err,msg:'获取失败',code:400}))
}


//获取分类数据
function getall(goods, onRetGot, onErrGot) {
    goodsModel.category(goods, (ret) => onRetGot({ret,code:200,total:""}), (err) => onErrGot({ err ,code:400}));
    
}

//根据字段排序
function sort(goods, onRetGot, onErrGot) {
    goodsModel.sort(goods, (ret) => onRetGot({ret,code:200,total:""}), (err) => onErrGot({ err ,code:400}));
    
}

function goodsall(goods, onRetGot, onErrGot) {
    goodsModel.goodsall(goods, (ret) => onRetGot({ret,code:200,total:""}), (err) => onErrGot({ err ,code:400}));
    
}

//模糊查询数据
function selectgoods(goods, onRetGot, onErrGot) {
    goodsModel.select(goods, (ret) => onRetGot({ret,code:200,total:""}), (err) => onErrGot({ err ,code:400}));
    
}


//添加商品
function addgoods(goods, onRetGot, onErrGot) {
    goodsModel.addgoods(goods,(ret)=>onRetGot({ret,code:200}),(err)=>onErrGot({err,code:400}))
}

//根据id数值删除商品
function deleteitem(goods, onRetGot, onErrGot) {
    goodsModel.deletegoods(goods, (ret) => onRetGot({ret,code:200}), (err) => onErrGot({ err ,code:400}));
    
}

function updatitem(goods, onRetGot, onErrGot) {
    console.log(goods);
    goodsModel.updategoods(goods, (ret) => onRetGot({ret,code:200}), (err) => onErrGot({ err ,code:400}));
    
}


const userController = {
    getitem,
    getall,
    deleteitem,
    addgoods,
    updatitem,
    selectgoods,
    goodsall,
    sort
};
module.exports = userController;